package algorithm.eightQueen;

import java.util.ArrayList;
import java.util.List;

public class nQueen {

  /**
   * 8x8棋盘放8个皇后，不能互相攻击 即任意两个皇后都不能处于同一行、同一列或同一斜线上 问有多少种摆法
   * <p>
   * 支持输入一种，和数量统计 支持n皇后，输出所有和数量统计
   */
  public static final int num = 16;
  public static int count = 0;
  public static List<List<Queen>> checkerBoard = new ArrayList<>(num);

  public static boolean check(Queen queen2) {
    for (int i = 0; i < num; i++) {
      for (int j = 0; j < num; j++) {
        Queen queen = checkerBoard.get(i).get(j);
        if (queen.val != 0) {
          if (queen.x == queen2.x || queen.y == queen2.y) {
            return false;
          }
          if (Math.abs(queen.x - queen2.x) == Math.abs(queen.y - queen2.y)) {
            return false;
          }
        }
      }
    }
    return true;
  }

  public static void init() {
    checkerBoard = new ArrayList<>(num);
    for (int i = 0; i < num; i++) {
      List<Queen> list = new ArrayList<>(num);
      for (int j = 0; j < num; j++) {
        Queen queen = new Queen();
        list.add(queen);
      }
      checkerBoard.add(list);
    }
  }

  public static void print() {
    for (int i = 0; i < num; i++) {
      for (int j = 0; j < num; j++) {
        System.out.print(checkerBoard.get(i).get(j).val + " ");
      }
      System.out.println();
    }
    System.out.println(count);

  }
}
